<!--
**********************************************************
* @Author: 张小平
* @Date:   2024-05-01
* @Email:  qqshuqian@163.com
* @Last modified: 最后修改日期
* @Description: 文件描述
**********************************************************
-->
<template>
  <basic-container>
    <avue-crud
      ref="crud"
      v-model:page="page"
      :table-loading="tableLoading"
      :data="tableData"
      :option="tableOption"
      @on-load="getList"
      @refresh-change="refreshChange"
      @size-change="sizeChange"
      @current-change="currentChange"
    ></avue-crud>
  </basic-container>
</template>

<script>
import {pageTableColumn} from "@/framework-admin/api/code/generator";
import {tableColumnOption} from "./generator";

export default {
  name: "tableColumnInfo",
  props: {
    queryData: {}
  },
  data() {
    return {
      tableLoading: false,
      tableData: [],
      tableOption: tableColumnOption,
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      }
    };
  },
  methods: {
    getList(page) {
      this.tableLoading = true;
      return pageTableColumn(
        this.buildParam(page)
      ).then(response => {
        this.tableData = response.data.data.records;
        this.page.total = response.data.data.total;
        this.tableLoading = false;
      });

    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    },
    refreshChange() {
      this.getList(this.page);
    },
    buildParam(page,sorts) {
      var entity = Object.assign(
        {},
        {},
        this.queryData
      );

      var obj = {
        pageNum: page.currentPage,
        pageSize: page.pageSize,
        sorts: sorts
      };
      obj.entity = entity;
      if (this.beforParam) {
        this.beforParam(obj.entity);
      }
      // if( this.sortData.sort){
      //   obj.sort = this.sortData.sort
      //   obj.order = (this.sortData.order||"dascending")=="dascending"?"desc":"asc";
      // }
      return obj;
    }
  }
};
</script>
